package library.operation;

import library.Book;
import library.ListBook;

import java.util.Scanner;
//借书操作类
public class BorrowOperation implements IOperation{
    @Override
    public void work(ListBook listBook) {
        System.out.print("请输入你要借阅图书的序号：");
        Scanner scanner = new Scanner(System.in);
        int index = scanner.nextInt();
        //注意输入的序号是否合法
        if(index < 0 && index >= listBook.getSize()){
            System.out.println("输入的序号非法！");
            return;
        }
        //注意该书是否借出，借出，则不能再借
        Book book = listBook.getBook(index);
        if(book.isBorrow()){
            System.out.println("这本书已借出，无法借阅");
            return;
        }
        //借书，将该书isBorrow设置为true
        book.setBorrow(true);
        System.out.println("借阅成功！");
    }
}
